package com.tanhua.model.vo;

import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.mongo.Visitors;
import com.tanhua.model.mongo.Voice;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;

import java.io.Serializable;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class VoiceVo implements Serializable {

    private Integer id; //用户id
    private String avatar; //头像
    private String nickname; //昵称
    private Integer age;
    private String soundUrl; //音频文件，URL
    private Integer remainingTimes ; //剩余次数

    /**
     * 在vo对象中，补充一个工具方法，封装转化过程
     */
    public static VoiceVo init(UserInfo userInfo, Voice voice,Integer count) {
        Long userId = voice.getUserId();
        Integer value = Integer.valueOf(String.valueOf(userId));
        VoiceVo voiceVo = new VoiceVo();
        voiceVo.setAvatar(userInfo.getAvatar());
        voiceVo.setNickname(userInfo.getNickname());
        voiceVo.setSoundUrl(voice.getVoiceUrl());
        voiceVo.setId(value);
        voiceVo.setAge(userInfo.getAge());
        voiceVo.setRemainingTimes(count);
        return voiceVo;
    }
}
